package app;


import com.alibaba.fastjson.JSON;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;


public class Product {
    public static void main(String[] args) {
        //获得路径及产生日志数目
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要产生的日志条目数");
        String num = sc.nextLine();
        System.out.println("请输入你要保存文件的路径");
        String path = sc.nextLine();
        int number = Integer.parseInt(num);
        //产生日志到文件
        File outFile = new File(path);
        if (outFile.exists()) {
            FileOutputStream outputStream = null;
            ProductApp productApp = new ProductApp();
            for (int i = 0; i < number; i++) {
                Pojo_arry app = productApp.getApp();
                String j = JSON.toJSONString(app);
                try {
                    outputStream = new FileOutputStream(outFile,true);
                    outputStream.write((j + "\n").getBytes());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("文件生成成功");
        }

    }
}



